#pragma once
#include "HashTable.h"

namespace bit
{
	template<class K, class V>
	class unordered_map
	{
		struct KeyOfmap
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef typename HashTable<K, pair<const K, V>, KeyOfmap>::iterator iterator;
		typedef typename HashTable<K, pair<const K, V>, KeyOfmap>::const_iterator const_iterator;

		iterator begin()
		{
			return _hash.begin();
		}

		iterator end()
		{
			return _hash.end();
		}

		const_iterator begin()const
		{
			return _hash.begin();
		}

		const_iterator end()const
		{
			return _hash.end();
		}

		pair <iterator, bool> Insert(const pair<K, V>& kv)
		{
			return _hash.Insert(kv);
		}

		V& operator[](const K& key)
		{
			pair<typename HashTable<K, pair<const K, V>, KeyOfmap>::iterator, bool>ret = _hash.Insert(make_pair(key,V()));
			return ret.first->second;
		}


		bool erase(const K& key)
		{
			return _hash.erase(key);
		}

	private:
		HashTable<K, pair<const K, V>, KeyOfmap>_hash;
	};
}